package a1_4;

/**
 * 订单详情类，关联订单和商品，包含数量及计算方法
 */
public class OrderDetail {
    private int quantity;       // 商品数量
    private Order order;        // 关联订单（多对一）
    private Product product;    // 关联商品（多对一）

    public OrderDetail() {}

    public OrderDetail(int quantity, Order order, Product product) {
        this.quantity = quantity;
        this.order = order;
        this.product = product;
    }

    // 操作方法：计算小计（商品单价 × 数量）
    public double calculateSubTotal() {
        return product.getPriceForQuantity(quantity);
    }

    // 操作方法：计算商品总重量（商品单重 × 数量）
    public double calculateWeight() {
        return product.getWeight() * quantity;
    }

    // Getter/Setter
    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }
}